package Thread2;

/**
 * @Author wangzhipeng
 * @Date 2020-08-21 10:44 上午
 * @Description
 */
public class StaticLockDemo {
    public static void main(String[] args) {
        B b = new B();

        Thread t1 = new Thread(){
            @Override
            public void run() {
                b.method1();
            }
        };
        Thread t2 = new Thread(){
            @Override
            public void run() {
                b.method2();
            }
        };

        t1.start();
        t2.start();

    }
}

class B{
    public static synchronized void method1(){
        System.out.println("方法1 运行");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("方法1 完成");

    }
    public synchronized void method2(){
        System.out.println("方法2 运行");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("方法2 完成");

    }


}
